//
//  Car.m
//  Chapt10_CarPartsInit_v10-01
//
//  Created by Ronald Ram on 14/02/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Car.h"
#import "Engine.h"
#import "Tire.h"


@implementation Car

-(id) init
{
    if ( self = [super init] )
    {
        tires = [[NSMutableArray alloc] init];
        
        for (int i=0; i<4; ++i) 
        {
            [tires addObject: [NSNull null] ];
        }
    }
    
    return (self);
}


-(void) dealloc
{
    [tires release];
    [engine release];
    
    [super dealloc];
}


//M001:
-(void) setEngine:(Engine *) newEngine
{
    [newEngine retain];
    [engine release];
    
    engine = newEngine;
}

//M002:
-(Engine *) engine
{
    return (engine);
}


//M003:
-(void) setTire:(Tire *) tire atIndex: (int) index
{
    [ tires replaceObjectAtIndex:index withObject: tire ];
}

//M004:
-(Tire *) tireAtIndex:(int)index
{
    //Tire *tire = [ tires objectAtIndex:index ];
    //return (tire);
    
    return ( [tires objectAtIndex:index] );
}

//M005:
-(void) print
{
    //print 4 tires...
    for (int i=0; i<4; ++i) 
    {
        NSLog( @"%@", [self tireAtIndex:i] );
    }
    
    NSLog( @"%@", engine ); //print engine...
}

@end
